package top.wardyan.wtask.ctrl;

import java.util.List;
import java.util.function.Predicate;

import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import top.wardyan.common.ctrl.BaseController;
import top.wardyan.wtask.feishu.api.FeishuMsgBusiness;
import top.wardyan.wtask.jobs.FeishuCheckJob;
import top.wardyan.wtask.service.IProcService;
import top.wardyan.wtask.tapd.api.TapdBusiness;

@Path("/empl")
public class EmplCtrl extends BaseController{

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();

	@Inject FeishuMsgBusiness feishuBusiness;
	@Inject TapdBusiness tapdBusiness;
	@Inject IProcService procService;
	@Inject FeishuCheckJob checkJob;
	
	public void list() {
		List<Record> empls = procService.yp_listempls(true);
		this.set("empls", empls);
		this.renderTemplate("list.html");
	}
	

	public void show(Integer sID) {
		List<Record> empls = procService.yp_listempls(true);
		java.util.Optional<Record> ot = empls.stream().filter(new Predicate<Record>() {

			@Override
			public boolean test(Record t) {
				
				return sID.equals(t.getInt("sID"));
			}
			
		}).findFirst();
		Record empl = new Record();
		if(ot != null && ot.isPresent()) {
			empl = ot.get();
		}
		this.set("empl", empl);
		this.renderTemplate("show.html");
	}
	
	public void save(Integer sID, String xCode, String xName, Boolean xIsCount, Float xCountRate, String xGroup, Integer xGroupIndex, Boolean xIsNotice, Boolean xIsCountTapd) {
		Record e = new Record();
		e.set("sID", sID);
		e.set("xCode", xCode);
		e.set("xName", xName);
		e.set("xIsCount", xIsCount);
		e.set("xCountRate", xCountRate);
		e.set("xGroup", xGroup);
		e.set("xGroupIndex", xGroupIndex);
		e.set("xIsNotice", xIsNotice);
		e.set("xIsCountTapd", xIsCountTapd);
		Db.update("yt_feishu_empl", "sID", e);
		this.show(sID);
	}
	
	public void del(Integer sID) {
		Db.deleteById("yt_feishu_empl", "sID", sID);
		this.list();
	}
	
}
